package com.authine.cloudpivot.web.api.secondopen.controller;

import com.alibaba.fastjson.JSON;
import com.authine.cloudpivot.engine.api.facade.BizObjectFacade;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectCreatedModel;
import com.authine.cloudpivot.engine.api.model.runtime.WorkflowInstanceModel;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.enums.ProcessType;
import com.authine.cloudpivot.web.api.secondopen.domain.*;
import com.authine.cloudpivot.web.api.secondopen.modules.QadResultVO;
import com.authine.cloudpivot.web.api.secondopen.modules.VoucherDeatailVO;
import com.authine.cloudpivot.web.api.secondopen.modules.VoucherVO;
import com.authine.cloudpivot.web.api.secondopen.service.BudgetMaintainService;
import com.authine.cloudpivot.web.api.secondopen.service.QadInterfaceService;
import com.authine.cloudpivot.web.api.secondopen.service.ReimburseService;
import com.authine.cloudpivot.web.api.secondopen.vo.ProhibitionTimeVO;
import com.authine.cloudpivot.web.api.utils.DateUtil;
import com.authine.cloudpivot.web.api.utils.StringUtils;
import io.jsonwebtoken.lang.Collections;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 报销维护控制器
 *
 */
@Api(value = "二开接口", tags = "报销维护控制器")
@RestController
@RequestMapping("/api/reimburseMaintain")
public class ReimburseController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(ReimburseController.class);

    @Autowired
    private BudgetMaintainService budgetMaintainService;

    @Autowired
    private ReimburseService reimburseService;

    /**
     * 报销扣减额度和驳回还原额度
     *
     * @param objId
     * @return
     */
    @RequestMapping(value="/wbxcbxAdjustLimit",method = {RequestMethod.POST ,RequestMethod.GET })
    @ApiOperation(value = "报销扣减额度和驳回还原额度", notes = "报销扣减额度和驳回还原额度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objId", value = "业务对象id", dataType = "String", paramType = "query")
    })
    public void wbxcbxAdjustLimit(String objId,String processCode,String identtify) {
        log.info("获取参数:objId={},processCode={},identtify={}", objId,processCode,identtify);
        if (StringUtils.isBlank(objId) || StringUtils.isBlank(processCode) || StringUtils.isBlank(identtify)) {
            log.info("参数不完整，直接结束");
            return;
        }
        String processName="";
        if("wbxcbxdlc".equals(processCode)){
            processName="外埠行车报销单";
        }else if("clfbxlc".equals(processCode)){
            processName="差旅费报销单";
        }

        BizObjectFacade bizObjectFacade = super.getBizObjectFacade();
        //获取业务数据
        BizObjectCreatedModel bizObject = bizObjectFacade.getBizObject(processCode, objId);
        if (bizObject == null) {
            log.info("业务对象不存在");
            return;
        }
        String wId = bizObject.getWorkflowInstanceId();
        log.info("TargetOwner:wId={}", wId);
        WorkflowInstanceModel wiModel = super.getWorkflowInstanceFacade().getWorkflowInstance(wId);
        if (wiModel == null) {
            log.info("业务流程对象不存在");
        }

        String cbzx = (String) bizObject.get("cbzx");
        String oneSubjectCode = (String) bizObject.get("oneSubjectCode");
        String twoSubjectCode = (String) bizObject.get("twoSubjectCode");
        String year=String.valueOf(DateUtil.getCurrentYear());


        Monthlybudgetadjustrecord monthlybudgetadjustrecord=new Monthlybudgetadjustrecord();
        monthlybudgetadjustrecord.setYear(year);

        monthlybudgetadjustrecord.setOneSubject(oneSubjectCode);
        monthlybudgetadjustrecord.setTwoSubject(twoSubjectCode);
        monthlybudgetadjustrecord.setCostCenter(cbzx);
        monthlybudgetadjustrecord.setMonth(String.valueOf(DateUtil.getCurrentMonth()));

        BigDecimal ys=(BigDecimal) bizObject.get("hjbxje");
        //如果是驳回
        if("2".equals(identtify)){
            ys=ys.multiply(new BigDecimal(-1));
        }
        monthlybudgetadjustrecord.setAdjustmentLimit(ys);
        monthlybudgetadjustrecord.setModifiedBy("admin");
        monthlybudgetadjustrecord.setModifiedTime(new Date());
        //报销更改中间表额度
        int a=budgetMaintainService.ReimburseBudget(monthlybudgetadjustrecord);
        if(a>0){
            log.info("-----------"+processName+"更改预算成功--------{}", JSON.toJSONString(monthlybudgetadjustrecord));
            BudgetLog budgetLog=new BudgetLog();
            //插入日志信息
            BeanUtils.copyProperties(monthlybudgetadjustrecord,budgetLog);
            if("1".equals(identtify)){
                budgetLog.setReductionLimit((BigDecimal) bizObject.get("hjbxje"));
                budgetLog.setIncreaseLimit(new BigDecimal(0));
            }else{
                budgetLog.setIncreaseLimit((BigDecimal) bizObject.get("hjbxje"));
                budgetLog.setReductionLimit(new BigDecimal(0));
            }
            budgetLog.setProcessId(objId);
            if("wbxcbxdlc".equals(processCode)){
                //如果是外埠行车报销单
                budgetLog.setProcessType(ProcessType.WBXCBX.getCode());
            }else if("clfbxlc".equals(processCode)){
                //如果是差旅费报销单
                budgetLog.setProcessType(ProcessType.CLFBX.getCode());
            }

            budgetMaintainService.addBudgetLog(budgetLog);
        }else{
            log.info("-----------"+processName+"更改预算失败--------{}", JSON.toJSONString(monthlybudgetadjustrecord));
        }

    }


    /**
     * 零星票据报销扣减额度和驳回还原额度
     *
     * @param objId
     * @return
     */
    @RequestMapping(value="/lxpjbxAdjustLimit",method = {RequestMethod.POST ,RequestMethod.GET })
    @ApiOperation(value = "零星票据报销扣减额度和驳回还原额度", notes = "零星票据报销扣减额度和驳回还原额度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objId", value = "业务对象id", dataType = "String", paramType = "query")
    })
    public void lxpjbxAdjustLimit(String objId,String processCode,String identtify) {
        log.info("获取参数:objId={},processCode={},identtify={}", objId,processCode,identtify);
        if (StringUtils.isBlank(objId) || StringUtils.isBlank(processCode) || StringUtils.isBlank(identtify)) {
            log.info("参数不完整，直接结束");
            return;
        }
        String processName="零星票据报销单";

        BizObjectFacade bizObjectFacade = super.getBizObjectFacade();
        //获取业务数据
        BizObjectCreatedModel bizObject = bizObjectFacade.getBizObject(processCode, objId);
        if (bizObject == null) {
            log.info("业务对象不存在");
            return;
        }
        String wId = bizObject.getWorkflowInstanceId();
        log.info("TargetOwner:wId={}", wId);
        WorkflowInstanceModel wiModel = super.getWorkflowInstanceFacade().getWorkflowInstance(wId);
        if (wiModel == null) {
            log.info("业务流程对象不存在");
        }
        //是否关联B表
        boolean sfglbb = (Boolean) bizObject.get("sfglbb");
        System.out.println("----------------sfglbb----------------"+sfglbb);
        //如果关联了B表，则扣除B表额度
        if(sfglbb){
            List<Map<String, Object>> bTableSheets=(List<Map<String, Object>>) bizObject.get("bTableSheet");
            if(!Collections.isEmpty(bTableSheets)) {
                for (int i = 0; i < bTableSheets.size(); i++) {
                    String bId = String.valueOf(bTableSheets.get(i).get("bId"));
                    BigDecimal hjbxje = (BigDecimal)bTableSheets.get(i).get("cdje");
                    //如果是驳回
                    if("2".equals(identtify)){
                        hjbxje=hjbxje.multiply(new BigDecimal(-1));
                    }
                    Iusi6BmsqsB iusi6BmsqsB=new Iusi6BmsqsB();
                    iusi6BmsqsB.setSsed(hjbxje);
                    iusi6BmsqsB.setId(bId);
                    iusi6BmsqsB.setModifier("admin");
                    if(reimburseService.kjBTableBudget(iusi6BmsqsB)>0){
                        log.info("-----------"+processName+"维护B表预算信息数据成功--------该条数据为:{}",JSON.toJSONString(iusi6BmsqsB));
                    }
                }
            }

//            //合计报销金额
//            BigDecimal hjbxje = (BigDecimal) bizObject.get("hjbxje");
//            //B表Id
//            String bId = (String) bizObject.get("bId");
//            //如果是驳回
//            if("2".equals(identtify)){
//                hjbxje=hjbxje.multiply(new BigDecimal(-1));
//            }
//            Iusi6BmsqsB iusi6BmsqsB=new Iusi6BmsqsB();
//            iusi6BmsqsB.setSsed(hjbxje);
//            iusi6BmsqsB.setId(bId);
//            iusi6BmsqsB.setModifier("admin");
//            if(reimburseService.kjBTableBudget(iusi6BmsqsB)>0){
//                log.info("-----------"+processName+"维护B表预算信息成功--------{}", JSON.toJSONString(iusi6BmsqsB));
//            }else{
//                log.info("-----------"+processName+"维护B表预算信息失败--------{}", JSON.toJSONString(iusi6BmsqsB));
//            }

        }



        String cbzx = (String) bizObject.get("cbzx");
//        String oneSubjectCode = (String) bizObject.get("oneSubjectCode");
//        String twoSubjectCode = (String) bizObject.get("twoSubjectCode");
        String year=String.valueOf(DateUtil.getCurrentYear());
        String month=String.valueOf(DateUtil.getCurrentMonth());
        List<Map<String, Object>> lxbxdSheetList=(List<Map<String, Object>>) bizObject.get("lxbxdSheet");
        if(!Collections.isEmpty(lxbxdSheetList)) {
            for (int i = 0; i < lxbxdSheetList.size(); i++) {
                //是否费控
                String isfk = String.valueOf(lxbxdSheetList.get(i).get("isfk"));
                if(StringUtils.isBlank(isfk) || "否".equals(isfk)){
                    log.info("科目为非费控科目，不进行扣减预算，流程id为{}",objId);
                    //不进行预算扣减
                    continue;
                }

                String oneSubjectCode = String.valueOf(lxbxdSheetList.get(i).get("zzhbm"));
                String twoSubjectCode = String.valueOf(lxbxdSheetList.get(i).get("fzhbm"));
                BigDecimal ys = (BigDecimal) lxbxdSheetList.get(i).get("zsrmbje");
                //如果是驳回
                if("2".equals(identtify)){
                    ys=ys.multiply(new BigDecimal(-1));
                }
                Monthlybudgetadjustrecord monthlybudgetadjustrecord=new Monthlybudgetadjustrecord();
                monthlybudgetadjustrecord.setYear(year);
                monthlybudgetadjustrecord.setOneSubject(oneSubjectCode);
                monthlybudgetadjustrecord.setTwoSubject(twoSubjectCode);
                monthlybudgetadjustrecord.setCostCenter(cbzx);
                monthlybudgetadjustrecord.setMonth(month);
                monthlybudgetadjustrecord.setAdjustmentLimit(ys);
                monthlybudgetadjustrecord.setModifiedBy("admin");
                monthlybudgetadjustrecord.setModifiedTime(new Date());
                //报销更改中间表额度
                int a=budgetMaintainService.ReimburseBudget(monthlybudgetadjustrecord);
                if(a>0){
                    log.info("-----------"+processName+"更改预算成功--------{}", JSON.toJSONString(monthlybudgetadjustrecord));
                    BudgetLog budgetLog=new BudgetLog();
                    //插入日志信息
                    BeanUtils.copyProperties(monthlybudgetadjustrecord,budgetLog);
                    if("1".equals(identtify)){
                        budgetLog.setReductionLimit((BigDecimal) bizObject.get("hjbxje"));
                        budgetLog.setIncreaseLimit(new BigDecimal(0));
                    }else{
                        budgetLog.setIncreaseLimit((BigDecimal) bizObject.get("hjbxje"));
                        budgetLog.setReductionLimit(new BigDecimal(0));
                    }
                    budgetLog.setProcessId(objId);
                    budgetLog.setProcessType(ProcessType.LXPJBX.getCode());

                    budgetMaintainService.addBudgetLog(budgetLog);
                }else{
                    log.info("-----------"+processName+"更改预算失败--------{}", JSON.toJSONString(monthlybudgetadjustrecord));
                }
            }
        }

    }



    /**
     * 汇款申请扣减额度和驳回还原额度
     *
     * @param objId
     * @return
     */
    @RequestMapping(value="/hksqAdjustLimit",method = {RequestMethod.POST ,RequestMethod.GET })
    @ApiOperation(value = "汇款申请扣减额度和驳回还原额度", notes = "汇款申请扣减额度和驳回还原额度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objId", value = "业务对象id", dataType = "String", paramType = "query")
    })
    public void hksqAdjustLimit(String objId,String processCode,String identtify) {
        log.info("获取参数:objId={},processCode={},identtify={}", objId,processCode,identtify);
        if (StringUtils.isBlank(objId) || StringUtils.isBlank(processCode) || StringUtils.isBlank(identtify)) {
            log.info("参数不完整，直接结束");
            return;
        }
        String processName="汇款申请单";
        BizObjectFacade bizObjectFacade = super.getBizObjectFacade();
        //获取业务数据
        BizObjectCreatedModel bizObject = bizObjectFacade.getBizObject(processCode, objId);
        if (bizObject == null) {
            log.info("业务对象不存在");
            return;
        }
        String wId = bizObject.getWorkflowInstanceId();
        log.info("TargetOwner:wId={}", wId);
//        WorkflowInstanceModel wiModel = super.getWorkflowInstanceFacade().getWorkflowInstance(wId);
//        if (wiModel == null) {
//            log.info("业务流程对象不存在");
//        }



        String cbzx = (String) bizObject.get("cbzx");
        String oneSubjectCode = (String) bizObject.get("zzhbm");
        String twoSubjectCode = (String) bizObject.get("fzhbm");
        String year=String.valueOf(DateUtil.getCurrentYear());
        //是否关联B表
        boolean sfglbb = (Boolean) bizObject.get("sfglbb");
        //如果关联了B表，则扣除B表额度
        if(sfglbb){
            List<Map<String, Object>> bTableSheets=(List<Map<String, Object>>) bizObject.get("hkglbSheet");
            if(!Collections.isEmpty(bTableSheets)) {
                for (int i = 0; i < bTableSheets.size(); i++) {
                    String bId = String.valueOf(bTableSheets.get(i).get("bid"));
                    BigDecimal hjbxje = (BigDecimal)bTableSheets.get(i).get("cdje");
                    //如果是驳回
                    if("2".equals(identtify)){
                        hjbxje=hjbxje.multiply(new BigDecimal(-1));
                    }
                    Iusi6BmsqsB iusi6BmsqsB=new Iusi6BmsqsB();
                    iusi6BmsqsB.setSsed(hjbxje);
                    iusi6BmsqsB.setId(bId);
                    iusi6BmsqsB.setModifier("admin");
                    if(reimburseService.kjBTableBudget(iusi6BmsqsB)>0){
                        log.info("-----------"+processName+"维护B表预算信息数据成功--------该条数据为:{}",JSON.toJSONString(iusi6BmsqsB));
                    }
                }
            }
        }

        String fklx = (String) bizObject.get("fklx");
        if(!"票到付款".equals(fklx)){
            log.info("预付款或已挂账付款不进行额度调整");
            return;
        }

        //是否费控
        String isfk = (String) bizObject.get("isfk");
        if(StringUtils.isBlank(isfk) || "否".equals(isfk)){
            log.info("汇用款申请单科目为非费控科目，不进行扣减预算，流程id为{}",objId);
            //不进行预算扣减
            return;
        }


        Monthlybudgetadjustrecord monthlybudgetadjustrecord=new Monthlybudgetadjustrecord();
        monthlybudgetadjustrecord.setYear(year);

        monthlybudgetadjustrecord.setOneSubject(oneSubjectCode);
        monthlybudgetadjustrecord.setTwoSubject(twoSubjectCode);
        monthlybudgetadjustrecord.setCostCenter(cbzx);
        monthlybudgetadjustrecord.setMonth(String.valueOf(DateUtil.getCurrentMonth()));

        BigDecimal ys=(BigDecimal) bizObject.get("jine");
        //如果是驳回
        if("2".equals(identtify)){
            ys=ys.multiply(new BigDecimal(-1));
        }
        monthlybudgetadjustrecord.setAdjustmentLimit(ys);
        monthlybudgetadjustrecord.setModifiedBy("admin");
        monthlybudgetadjustrecord.setModifiedTime(new Date());
        //报销更改中间表额度
        int a=budgetMaintainService.ReimburseBudget(monthlybudgetadjustrecord);
        if(a>0){
            log.info("-----------"+processName+"更改预算成功--------{}", JSON.toJSONString(monthlybudgetadjustrecord));
            BudgetLog budgetLog=new BudgetLog();
            //插入日志信息
            BeanUtils.copyProperties(monthlybudgetadjustrecord,budgetLog);
            if("1".equals(identtify)){
                budgetLog.setReductionLimit((BigDecimal) bizObject.get("jine"));
                budgetLog.setIncreaseLimit(new BigDecimal(0));
            }else{
                budgetLog.setIncreaseLimit((BigDecimal) bizObject.get("jine"));
                budgetLog.setReductionLimit(new BigDecimal(0));
            }
            budgetLog.setProcessId(objId);
            budgetLog.setProcessType(ProcessType.HKSQ.getCode());
            budgetMaintainService.addBudgetLog(budgetLog);
        }else{
            log.info("-----------"+processName+"更改预算失败--------{}", JSON.toJSONString(monthlybudgetadjustrecord));
        }

    }



    /**
     * 报销冲抵借款单提交扣减借款金额和驳回还原借款金额
     *
     * @param objId
     * @return
     */
    @RequestMapping(value="/loanQuotaMaintain",method = {RequestMethod.POST ,RequestMethod.GET })
    @ApiOperation(value = "报销冲抵借款单提交扣减借款金额和驳回还原借款金额", notes = "报销冲抵借款单提交扣减借款金额和驳回还原借款金额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objId", value = "业务对象id", dataType = "String", paramType = "query")
    })
    public void loanQuotaMaintain(String objId,String processCode,String identtify) {
        log.info("获取参数:objId={},processCode={},identtify={}", objId,processCode,identtify);
        if (StringUtils.isBlank(objId) || StringUtils.isBlank(processCode) || StringUtils.isBlank(identtify)) {
            log.info("参数不完整，直接结束");
            return;
        }
        BizObjectFacade bizObjectFacade = super.getBizObjectFacade();
        //获取业务数据
        BizObjectCreatedModel bizObject = bizObjectFacade.getBizObject(processCode, objId);
        if (bizObject == null) {
            log.info("业务对象不存在");
            return;
        }
        String wId = bizObject.getWorkflowInstanceId();
        log.info("TargetOwner:wId={}", wId);
        WorkflowInstanceModel wiModel = super.getWorkflowInstanceFacade().getWorkflowInstance(wId);
        if (wiModel == null) {
            log.info("业务流程对象不存在");
        }

        boolean isgljkd = (Boolean) bizObject.get("isgljkd");
        //如果没有关联借款单
        if(!isgljkd){
            log.info("该表单未开启关联借款单流程");
            return;
        }
        List<Map<String, Object>> jkdSheetList=new ArrayList<>();

        if("clfbxlc".equals(processCode)){
            //如果是差旅费报销单
            jkdSheetList = (List<Map<String, Object>>) bizObject.get("clfjkdSheet");
        }else if("lxpjbxlc".equals(processCode)){
            //如果是零星票据报销单
            jkdSheetList = (List<Map<String, Object>>) bizObject.get("jkdSheet");
        }
        log.info("冲抵借款单数据信息为{}",JSON.toJSONString(jkdSheetList));

        if(!Collections.isEmpty(jkdSheetList)){
            for (int i = 0; i < jkdSheetList.size(); i++) {
                String processId = String.valueOf(jkdSheetList.get(i).get("processId"));
                if(StringUtils.isBlank(processId)){
                    continue;
                }
                BigDecimal cczj = (BigDecimal)jkdSheetList.get(i).get("cczj");
                Ie6s6Jkdlc ie6s6Jkdlc=new Ie6s6Jkdlc();
                ie6s6Jkdlc.setId(processId);
                //如果是提交冲抵借款金额
                if("1".equals(identtify)) {
                    ie6s6Jkdlc.setSyjkje(cczj);
                }else{
                    //如果是驳回还原借款金额
                    ie6s6Jkdlc.setSyjkje(cczj.multiply(new BigDecimal(-1)));
                }
                int a=reimburseService.loanQuotaAmount(ie6s6Jkdlc);
                if(a>0){
                    log.info("更新借款单借款金额成功，数据为{}",JSON.toJSONString(ie6s6Jkdlc));
                }else{
                    log.info("更新借款单借款金额失败，数据为{}",JSON.toJSONString(ie6s6Jkdlc));
                }

            }
        }

    }

    /**
     * 根据id查询B表剩余额度是否小于申请人填写的额度，小于则不让提交，参数：标题，id，剩余额度
     *
     */
    @PostMapping("/getBQuotaByParam")
    public AjaxResult getBQuotaByParam(@RequestBody List<Iusi6BmsqsB> iusi6BmsqsBs){

        log.info("---------------方法：getBudgetQuotaByParam："+ JSON.toJSONString(iusi6BmsqsBs));
        if(Collections.isEmpty(iusi6BmsqsBs)){
//            log.info("---------------方法：getBudgetQuotaByParam参数：年份："+qnyssq.getNf()+"，总账户编码："+qnyssq.getOneaccountcode()+",分帐户编码："+qnyssq.getTwoaccountcode()+"，成本中心："+qnyssq.getYscbzx());
            return AjaxResult.error(300,"参数有误，不能存在为空的参数");
        }
        for (Iusi6BmsqsB b : iusi6BmsqsBs) {
            //如果id为空或者剩余额度为空或者剩余金额为0
            if(StringUtils.isBlank(b.getId()) || b.getSsed()==null || b.getSsed().compareTo(BigDecimal.ZERO)==0){
                return AjaxResult.error(300,"参数有误，不能存在为空的Id或为空或0的冲抵额度");
            }
        }
        List<Iusi6BmsqsB> bmsqsBs=reimburseService.getBQuota(iusi6BmsqsBs);
        log.info("---------------返回信息："+ JSON.toJSONString(bmsqsBs));
        if(Collections.isEmpty(bmsqsBs)){
            return AjaxResult.error(300,"部门申请书B数据不存在");
        }else{
            for (Iusi6BmsqsB iusi6BmsqsB : iusi6BmsqsBs) {
                int i=0;
                for (Iusi6BmsqsB bmsqsB : bmsqsBs) {
                    if(iusi6BmsqsB.getId().equals(bmsqsB.getId())){
                        //如果id一样，则判断申请人填写的额度是否大于剩余额度，大于则不让提交
                        if(iusi6BmsqsB.getSsed().compareTo(bmsqsB.getSsed())==1){
                            return AjaxResult.error(300,"B表名称为"+iusi6BmsqsB.getName()+"额度不能大于剩余额度"+bmsqsB.getSsed());
                        }
                        break;
                    }
                    if(i==bmsqsBs.size()-1){
                        //如果没有查到额度信息
                        return AjaxResult.error(300,"B表名称为"+iusi6BmsqsB.getName()+"对应的流程信息不存在");
                    }
                    i++;
                }
            }
        }
        return AjaxResult.success("校验成功");
    }

    /**
     * 判断报销流程禁止时间
     */
    @RequestMapping("/getProhibitionTime")
    public AjaxResult getProhibitionTime(){
        Date nowdate = new Date();
        ProhibitionTimeVO pvo = new ProhibitionTimeVO();
        List<ProhibitionTimeVO> list = reimburseService.getProhibitionTime();
        if (!CollectionUtils.isEmpty(list)){
            for (int i = 0; i < list.size(); i++) {
                pvo=list.get(i);
            }
            Date startdate = pvo.getStartdate();
            Date enddate = pvo.getEnddate();
            boolean in = cn.hutool.core.date.DateUtil.isIn(nowdate, startdate, enddate);
            if(in){
                return AjaxResult.error(300,"当前流程已限制申请");
            }else {
                return AjaxResult.success("当前流程允许提交");
            }
        }else{
            return AjaxResult.success("当前流程允许提交");
        }


    }



    /**
     * 供应商预付款申请表申请扣减额度和驳回还原额度
     *
     * @param objId
     * @return
     */
    @RequestMapping(value="/gysyfksqLimitAdjustLimit",method = {RequestMethod.POST ,RequestMethod.GET })
    @ApiOperation(value = "供应商预付款申请表申请·扣减额度和驳回还原额度", notes = "供应商预付款申请表申请扣减额度和驳回还原额度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objId", value = "业务对象id", dataType = "String", paramType = "query")
    })
    public void gysyfksqLimitAdjustLimit(String objId,String processCode,String identtify) {
        log.info("获取参数:objId={},processCode={},identtify={}", objId,processCode,identtify);
        if (StringUtils.isBlank(objId) || StringUtils.isBlank(processCode) || StringUtils.isBlank(identtify)) {
            log.info("参数不完整，直接结束");
            return;
        }
        String processName="供应商预付款申请表";
        BizObjectFacade bizObjectFacade = super.getBizObjectFacade();
        //获取业务数据
        BizObjectCreatedModel bizObject = bizObjectFacade.getBizObject(processCode, objId);
        if (bizObject == null) {
            log.info("业务对象不存在");
            return;
        }
        String wId = bizObject.getWorkflowInstanceId();
        log.info("TargetOwner:wId={}", wId);
//        WorkflowInstanceModel wiModel = super.getWorkflowInstanceFacade().getWorkflowInstance(wId);
//        if (wiModel == null) {
//            log.info("业务流程对象不存在");
//        }

        String fklx = (String) bizObject.get("fklx");
        //是否关联B表
        boolean sfglbb = (Boolean) bizObject.get("sfglbb");
        if(!sfglbb){
            log.info("预付款不进行部门申请书B表调整");
            return;
        }

        List<Map<String, Object>> bTableSheets=(List<Map<String, Object>>) bizObject.get("yfkbSheet");
        if(!Collections.isEmpty(bTableSheets)) {
            for (int i = 0; i < bTableSheets.size(); i++) {
                String bId = String.valueOf(bTableSheets.get(i).get("bid"));
                BigDecimal hjbxje = (BigDecimal)bTableSheets.get(i).get("cdje");
                //如果是驳回
                if("2".equals(identtify)){
                    hjbxje=hjbxje.multiply(new BigDecimal(-1));
                }
                Iusi6BmsqsB iusi6BmsqsB=new Iusi6BmsqsB();
                iusi6BmsqsB.setSsed(hjbxje);
                iusi6BmsqsB.setId(bId);
                iusi6BmsqsB.setModifier("admin");
                if(reimburseService.kjBTableBudget(iusi6BmsqsB)>0){
                    log.info("-----------"+processName+"维护B表预算信息数据成功--------该条数据为:{}",JSON.toJSONString(iusi6BmsqsB));
                }
            }
        }

    }



}
